package com.juxuan.knowledge.controller;


import com.juxuan.knowledge.model.TestUser;
import com.juxuan.knowledge.service.TestUserService;
import com.sun.org.apache.bcel.internal.classfile.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/user")
public class TestUserController {

    @Autowired
    public TestUserService testUserService;


    @RequestMapping("/userAll")
    public void userAll(){

        List<TestUser> testUsers = testUserService.userAll();
        System.out.println(testUsers);

        //System.out.println(byUserName);
    }

    @RequestMapping("/login")
    public Map<String,Object> login(@RequestBody TestUser testUser){
        Map<String,Object> data = new HashMap<String,Object>();
        TestUser user = testUserService.getByUserName(testUser);
        if(null == user){
            data.put("code","1111");
            data.put("success","失败");
            data.put("data","账号不存在");
        }else{
            if(!user.getUserPassword().equals(testUser.getUserPassword())){
                data.put("code","1111");
                data.put("success","失败");
                data.put("data","密码错误");
            }else{
                data.put("code","0000");
                data.put("success","成功");
                data.put("data","验证成功");
            }
        }
        return data;
    }


}
